﻿Public Class frmQuanLiHocSinh

    Private Sub frmQuanLiHocSinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim hsBUS As New HocSinhBUS()
        Dim ds As List(Of HocSinhDTO)
        ds = HocSinhBUS.LayDSHocSinh()

        dgvDSHS.Rows.Clear()
        For Each hs As HocSinhDTO In ds
            dgvDSHS.Rows.Add(hs.MAHOCSINH, hs.TENHOCSINH, hs.GIOITINH, hs.NGAYSINH, hs.DIACHI, hs.SODT, hs.EMAIL, hs.MALOP)
        Next
        'dgvDSHS.DataSource = HocSinhBUS.SelectAll()
    End Sub

    Sub LoadDanhSach()
        dgvDSHS.DataSource = HocSinhBUS.SelectAll()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Try
            If (dgvDSHS.SelectedRows.Count > 0) Then
                Dim hsBUS As New HocSinhBUS()
                Dim row As DataGridViewRow = dgvDSHS.SelectedRows(0)
                Dim maLOP As Integer = Integer.Parse(row.Cells(0).Value)

                Dim frm As New frmSuaHoSoHocSinh()
                'frm.MaHS = maHS
                frm.txtTenHS.Text = row.Cells(1).Value.ToString()

                If row.Cells(2).Value.ToString() = "Nam" Then
                    frm.rbNam.Checked = True
                Else
                    frm.rbNu.Checked = True
                End If
                frm.txtNgaySinh.Text = row.Cells(3).Value.ToString()
                frm.txtDiaChi.Text = row.Cells(4).Value.ToString()
                'frm.dtpNgaySinh.Value = row.Cells(4).Value
                frm.txtSoDT.Text = row.Cells(5).Value.ToString()
                frm.txtEmail.Text = row.Cells(6).Value.ToString()
                'frm.MaLop = row.Cells(7).Value.ToString()
                'frm.MaLop = row.Cells(7).Value.ToString()
                'frm.MaCN = row.Cells(6).Value
                'frm.MaLop = row.Cells(7).Value.ToString()
                'frm.cboLop.Text = row.Cells(7).Value.ToString()
                frm.MaLop = maLOP
                frm.ShowDialog()

                Dim ds As List(Of HocSinhDTO)
                ds = HocSinhBUS.LayDSHocSinh()

                dgvDSHS.Rows.Clear()
                For Each hs As HocSinhDTO In ds
                    dgvDSHS.Rows.Add(hs.MAHOCSINH, hs.TENHOCSINH, hs.GIOITINH, hs.NGAYSINH, hs.DIACHI, hs.SODT, hs.EMAIL, hs.MALOP)
                Next
            End If
        Catch ex As Exception
        End Try
        'LoadDanhSach()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Try
            Dim hsBUS As New HocSinhBUS()
            If (dgvDSHS.SelectedRows.Count > 0) Then
                For Each row As DataGridViewRow In dgvDSHS.SelectedRows
                    Dim hsDAO As New HocSinhDTO
                    hsDAO.MAHOCSINH = Integer.Parse(row.Cells(0).Value)
                    'hsDTO.MAHOCSINH =
                    HocSinhBUS.XoaKhachHang(hsDAO)
                Next
                MessageBox.Show("Xóa thành công")
                Dim ds As List(Of HocSinhDTO)
                ds = HocSinhBUS.LayDSHocSinh()

                dgvDSHS.Rows.Clear()
                For Each hs As HocSinhDTO In ds
                    dgvDSHS.Rows.Add(hs.MAHOCSINH, hs.TENHOCSINH, hs.GIOITINH, hs.NGAYSINH, hs.DIACHI, hs.SODT, hs.EMAIL, hs.MALOP)
                Next
            End If
        Catch ex As Exception
            'MessageBox.Show("Lỗi: " + ex.Message)
        End Try
        'LoadDanhSach()
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
End Class